<template>
  <div class="order-detail-page" v-if="order">
    <!-- 操作栏 -->
    <DetailAction :order="order" />
    <!-- 步骤条 组件xtx-steps.vue-->
    <!-- 步骤条-->
    <DetailSteps :order="order"></DetailSteps>
    <!-- 物流栏 -->
    <!--
    实现Suspense
      将异步组件包装在<template #default>标记中
      在我们的Async组件的旁边添加一个兄弟姐妹，标签为<template #fallback>。
      将两个组件都包装在<suspense>组件中 -->

    <!-- 只有在状态为3,4,5的时候才显示物流栏 -->
    <Suspense v-if="[3, 4, 5]">
      <!-- 组件加载完毕 -->
      <template #default>
        <DetailLogistics :order="order"></DetailLogistics>
      </template>
      <!-- 组件加载中显示 -->
      <template #fallback>
        <div class="loading">loading...</div>
      </template>
    </Suspense>
    <!-- 订单商品信息 -->
    <OrderInfo :order='order'></OrderInfo>
  </div>
</template>

<script>
import { findOrderDetail } from '@/api/order'
import DetailAction from './components/detail-action'
import { useRoute } from 'vue-router'
import { ref } from 'vue'
import DetailSteps from './components/detail-steps.vue'
import DetailLogistics from './components/detail-logistics.vue'
import OrderInfo from './components/order-info.vue'
export default {
  name: 'OrderDetailPage',
  components: { DetailAction, DetailSteps, DetailLogistics, OrderInfo },
  setup () {
    const route = useRoute()
    // console.log(route.params.id)
    const order = ref(null)
    findOrderDetail(route.params.id).then(({ result }) => {
      console.log(result)
      order.value = result
    })

    return { order }
  }
}
</script>
<style scoped lang="less">
.order-detail-page {
  background: #fff;
  height: 100%;
}

.loading {
  height: 50px;
  display: flex;
  align-items: center;
  padding: 0 30px;
  background-color: #f5f5f5;
  margin: 30px 50px 0;
}
</style>
